package com.start.avue.mapper;


import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.start.avue.tools.AvueTools;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
import java.util.Map;

@Slf4j
public abstract class StartBaseAvueMapper implements StartAvueMapper {
    protected JSONObject column;
    protected Map<String, String> headers;
    protected String startHomeUrl;

    @Override
    public void init(String startHomeUrl, JSONObject column, Map<String, String> headers) {
        if (StringUtils.isAllBlank(startHomeUrl)) {
            startHomeUrl = "";
        }
        this.startHomeUrl = startHomeUrl;
        this.column = column;
        if (headers == null) {
            headers = new HashMap<>();
        }
        this.headers = headers;
    }

    @Override
    public JSONObject getColumnOption() {
        return column;
    }

    @Override
    public String getProp() {
        return column.getString("prop");
    }

    public static boolean strIsJson(String str) {
        return AvueTools.strIsJson(str);
    }

    public static boolean objIsJson(Object obj) {
        return AvueTools.objIsJson(obj);
    }

    public static JSONArray objectToJSONArray(Object value) {
        return AvueTools.objectToJSONArray(value);
    }
}
